//
//  ApplyFourthVC.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/18.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "ApplyFourthVC.h"
#import "ApplyOilFifthVC.h"
#import "ApplyeOilHeadView.h"
#import "OilCardAdditionalTableView.h"
#import "OilCardAdditional_IdCardCell.h"
#import "OilCardAdditional_CarCell.h"

@interface ApplyFourthVC () < UITableViewDelegate, UITableViewDataSource >

@property (nonatomic, strong) ApplyeOilHeadView *stepHeadView;
@property (nonatomic, strong) OilCardAdditionalTableView *tableView;
@end

@implementation ApplyFourthVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  //  [self setDefaltNavBar];
  [self.navigationController setNavigationBarHidden:NO animated:animated];
  [self setNavImage:[UIImage imageNamed:@"Home_BgImage"] titleColor:[UIColor whiteColor]];
  [self setStatusBarStyleWhite];
  
}


- (void)createFields {
  [super createFields];
  self.navigationItem.title = YTLocalizedString(@"油咭申请");
  [self createWhiteBack];
  
}

- (void)createViews {
  [super createViews];
  
  _tableView = [[OilCardAdditionalTableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - NavBarHeight - 50)];
  _tableView.delegate = self;
  _tableView.dataSource = self;
  [self.view addSubview:_tableView];
  
  _stepHeadView = [[ApplyeOilHeadView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * ITEMPRO)];
  _stepHeadView.stepCount = 1;
  _stepHeadView.userInteractionEnabled = NO;
  _stepHeadView.isPersonal = _applyModel.isPersonal;
  _tableView.tableHeaderView = _stepHeadView;

  
  ///! 取消
  UIButton *cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(0, _tableView.yt_bottom + 10, 30 * 5, 30)];
  [cancelButton setTitle:YTLocalizedString(@"上一步") forState:UIControlStateNormal];
  cancelButton.backgroundColor = DEF_GRAY;
  cancelButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  [cancelButton addTarget:self action:@selector(cancelclick) forControlEvents:UIControlEventTouchUpInside];
  cancelButton.yt_right = self.view.yt_centerX - 5;
  cancelButton.layer.masksToBounds = YES;
  cancelButton.layer.cornerRadius = 8;
  [self.view addSubview:cancelButton];
  
  ///! 下一步
  UIButton *nextStepButton = [[UIButton alloc] initWithFrame:CGRectMake(cancelButton.yt_right + 10, cancelButton.yt_top, cancelButton.yt_width, cancelButton.yt_height)];
  [nextStepButton setTitle:YTLocalizedString(@"下一步") forState:UIControlStateNormal];
  nextStepButton.backgroundColor = DEF_RED;
  nextStepButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  [nextStepButton addTarget:self action:@selector(nextclick) forControlEvents:UIControlEventTouchUpInside];
  nextStepButton.layer.masksToBounds = YES;
  nextStepButton.layer.cornerRadius = 8;
  [self.view addSubview:nextStepButton];

  
  
}

- (void)cancelclick {
  
}

- (void)nextclick {
  
  ApplyOilFifthVC *fifthVC = [[ApplyOilFifthVC alloc] init];
  fifthVC.applyModel = self.applyModel;
  [self.navigationController pushViewController:fifthVC animated:YES];
  
}

#pragma makr -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  if (section == 0) {
    if (_applyModel.isPersonal) {
      return 0;
    }
  }
  
  return 50;

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  
  UIView *contenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
  contenView.backgroundColor = [UIColor whiteColor];
  
  UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 110, 50)];
  titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
  titleLabel.textAlignment = NSTextAlignmentLeft;
  titleLabel.textColor = DEF_BLACK;
  [contenView addSubview:titleLabel];
  
  
  NSString *title = @"";
  
  if (section == 0) {
    if (_applyModel.isPersonal) {
      return nil;
    }
    title = YTLocalizedString(@"持k咭人身份证上传");
  } else {
    title = YTLocalizedString(@"车辆附件上传");
    
    ///! 查看样本
    UIButton *senderButton = [[UIButton alloc] initWithFrame:CGRectMake(titleLabel.yt_right, 30, 80, 20)];
    senderButton.titleLabel.font = [UIFont systemFontOfSize:11.0f];
    [senderButton setTitleColor:DEF_GRAY forState:UIControlStateNormal];
    [senderButton setTitle:YTLocalizedString(@"样本参考") forState:UIControlStateNormal];
    [senderButton setImage:[UIImage imageNamed:@"Oil_card_sample"] forState:UIControlStateNormal];
    [contenView addSubview:senderButton];
    [senderButton addTarget:self action:@selector(lookClick) forControlEvents:UIControlEventTouchUpInside];
    [senderButton layoutButtonWithEdgeInsetsStyle:WWButtonEdgeInsetsStyleRight imageTitleSpace:5];
  }
  titleLabel.text = title;
  return contenView;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  if (section == 0) {
    if (_applyModel.isPersonal) {
      return 0;
    } else {
      return 1;
    }
    
  } else {
    return 10;
  }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  if (indexPath.section == 0) {
    return 120;
  } else {
    return 160;
  }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  if (indexPath.section == 0) {
    static NSString *id_indentify = @"NewIdCell";
    OilCardAdditional_IdCardCell *cell = [tableView dequeueReusableCellWithIdentifier:id_indentify];
    if (!cell) {
      
      cell = [[OilCardAdditional_IdCardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:id_indentify];
    }
    
    
    return cell;
    
  } else {
    
    static NSString *indentify = @"NewCell";
    
    OilCardAdditional_CarCell *cell = [tableView dequeueReusableCellWithIdentifier:indentify];
    if (!cell) {
      cell = [[OilCardAdditional_CarCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentify];
      
    }
    
    return cell;

    
  }
  
}


#pragma mark -
- (void)lookClick {
  [SVProgressHUD showErrorWithStatus:@"点击查看样本"];
}

@end
